package com.lej.share

import android.app.Application
import com.lej.core.base.BaseInitializer
import com.lej.core.webView.jsInstances
import com.lej.share.webJs.ShareJsInstance
import com.umeng.analytics.MobclickAgent
import com.umeng.commonsdk.UMConfigure
import com.umeng.socialize.PlatformConfig

class LibShareInitializer : BaseInitializer() {
    override fun onInit(application: Application): Boolean {
        return true
    }

    override fun privacyInit(application: Application, isHave: Boolean) {
        if (!isHave) {
            UMConfigure.preInit(application, BuildConfig.UMENG_KEY, BuildConfig.UMENG_CHANNEL)
        } else {
            val isDebug = BuildConfig.DEBUG
            // 初始化SDK
            UMConfigure.init(
                application.applicationContext,
                BuildConfig.UMENG_KEY,
                BuildConfig.UMENG_CHANNEL,
                UMConfigure.DEVICE_TYPE_PHONE,
                null
            )
            UMConfigure.setLogEnabled(isDebug)
            // 选用AUTO页面采集模式
            MobclickAgent.setPageCollectionMode(MobclickAgent.PageMode.AUTO)

            jsInstances.add(::ShareJsInstance)

            val pkg = application.packageName
            PlatformConfig.setWeixin(BuildConfig.wx_id, BuildConfig.wx_secret)
            PlatformConfig.setWXFileProvider("$pkg.sharefileprovider")
            PlatformConfig.setQQZone(BuildConfig.qq_id, BuildConfig.qq_secret)
            PlatformConfig.setQQFileProvider("$pkg.sharefileprovider")
            PlatformConfig.setSinaWeibo(
                BuildConfig.sina_id,
                BuildConfig.sina_secret,
                "http://sns.whalecloud.com"
            )
            PlatformConfig.setSinaFileProvider("$pkg.sharefileprovider")
        }
    }
}